<template>
  <a-row class="card-nopd-out-container department-container">
    <a-col :span="3" class="tree-box process-chart">
      <makeListSide ref="makeListSideRef" @onSelect='onCardSelect' :listUrl="url.list" sideType="online" />
    </a-col>
    <a-col :span="21" class="table-box process-chart pt-20 pr-20">
      <div class='blue-line mb-20'>排产记录</div>
      <a-table :columns="columns" size="small" :dataSource="ieRoadmapRecordVOList" :pagination="false" :scroll="{y: 'calc(100vh - 300px)'}">
        <template #bodyCell="{ column, text, record}">
          <template v-if="column.key === 'lineId'">
            <!--            <span class="code-link" @click="viewDetail(record)">{{record.lineId}} </span>-->
            <span>{{getFieldText(lineList,record.lineId,'id','lineNo')}} </span>
          </template>
          <template v-if="column.key === 'processName'">
            <a-button type="link" class="primary-link" @click="viewDetails('process',record)"> {{record.processName}}</a-button>
          </template>
          <template v-if="column.key === 'roadmapName'">
            <a-button type="link" class="primary-link" @click="viewDetails('roadmap',record)"> {{record.roadmapName}}</a-button>
          </template>
          <template v-else-if="column.key === 'status'">
            <a-tag :color="'warning'" v-if="text === 1">{{$t('other.toSchedule')}}</a-tag>
            <a-tag :color="'success'" v-if="text === 2">{{$t('other.scheduled')}}</a-tag>
          </template>
          <template v-else-if="column.key === 'operate'">
<!--            排产中  已排产  {{$t('common.look')}}-->
            <span class="table-operate-container" v-if="record.status === 1 ">
              <a-button type="link" class="primary-link" @click="handleOperate('edit',record);updateCloudSchedule(record)">{{ $t('other.startSchedule') }}</a-button>
            </span>
            <span class="table-operate-container" v-if="record.status === 2 ">
                <a-button type="link" class="primary-link" @click="handleOperate('look',record)">{{ $t('other.viewAppl') }}</a-button>
            </span>
          </template>
        </template>
      </a-table>
    </a-col>
    <copyRouteModal ref="copyRouteModal" @ok="otherOperate" />
  </a-row>
</template>

<script>
import { ListMixinPm } from '@/mixin/listMixinPm.js'
import { listInnerColumns } from './newModules/config'
import copyRouteModal from '@/views/makeManage/routeChart/newModules/copyRouteModal.vue'
import makeListSide from '@/views/makeManage/makeProcess/newModules/makeListSide.vue'

import {  getFieldText } from '@/utils'
import axios from '@/utils/request'
import { message } from 'ant-design-vue';
// import getFieldText from '@/utils/index'

export default {
  name: 'autoSchedule',
  mixins: [ListMixinPm],
  components: { copyRouteModal, makeListSide },
  data () {
    return {
      url: {
        list: '/api/mo/ie-roadmap/page'
      },
      columns: listInnerColumns,
      ieRoadmapRecordVOList: [],
      selectMakeId: null,
      lineList: [],
    }
  },
  async created () {
    let res = await axios.postAction('/api/device/hanger-line/list')
    if (res.success){  this.lineList = res.data; }
    // console.log(this.lineList,'this.aaa-----------------------')
  },
  methods: {
    getFieldText,
    loadData () { },
    viewDetail (record) {
      this.$router.push({
        path: '/makeManage/makeProcess/details',
        query: { id: record.moId, processId: record.id }
      })
    },
    viewDetails (type, record) {
      if (type === 'process'){
        this.$router.push({
          path:'/makeManage/scheduleProcess/details',
          query: { id: record.id,'type':'ie' }
        })
      }else if(type === 'roadmap'){
        this.$router.push({
          path:'/makeManage/scheduleRoute/details',
          query: { id: record.roadmapId,'type':'ie' }
        })
      }
    },
    handleOperate (type, record) {
      if (type ==='edit'){
        this.$router.push({
          path:'/makeManage/scheduleProcess/edit',
          query: { id: record.id }
          // query: { id: record.moId, processId: record.id }
        })
      }
      if (type ==='look'){
        this.$router.push({
          path:'/makeManage/editSchedule/details',
          query: { id: record.id ,'type':'sch'}
        })
        console.log(record)
      }
      // console.log(type, record)
    },
    otherOperate () {
      this.$refs.makeListSideRef.loadData(true)
    },

    scheduleDel (record) {
      if (record.status === 0) {
        this.handleDelete(record.id, true, this.$t('other.sureDel')+'？', this.$t('common.del'))
      } else {
        message.error(this.$t('other.delFail'))
      }
    },
    goBack (id) {
      this.goBackTitle('/api/mo/auto-roadmap/cancel',id,this.$t('other.sureReturnDraft'))
    },
    async goBackTitle(url,id,text) {
      this.confirmChangeStatus(url,{id }, text, '提示', 'getAction')
    },
    handleCopy (id) {
      this.$refs.copyRouteModal.open(id)
    },
    updateCloudSchedule(record){
      // console.log(record)
      let params = {id:record.id,status:2}
      try {
        const res = axios.postAction('/api/mo/auto-roadmap/update-status',params)
        console.log(res)
      }catch (err){
        console.log(err)
      }

    },
    onCardSelect (record) {
      this.ieRoadmapRecordVOList = record.ieRoadmapRecordVOList || []
      this.selectMakeId = record.id
    }
  },

}
</script>